#!/bin/bash

REPO_ROOT="/remote/iosg/home-8/bot-hft/jenkins/workspace/coin2_feed_stats/coin"
cd "${REPO_ROOT}"

if [ -n "${1}" ]; then
  TRADING_DATE="${1}"
else
  TRADING_DATE="$(TZ=Asia/Shanghai date '+%Y%m%d')"
fi

START_DATE="${TRADING_DATE}"
END_DATE="$(date --date=@$(( $(date +%s --date=${START_DATE}) + 86400 )) '+%Y%m%d')"

echo "START_DATE=${START_DATE}"
echo "END_DATE=${END_DATE}"

source /remote/iosg/home-8/bot-hft/miniconda3/etc/profile.d/conda.sh
conda activate /remote/iosg/home-8/bot-hft/miniconda3/envs/coin2_motion_env_migration
cd python

./pyrunner coin/support/feed_tool/feed_stats/app/feed_stats_motion/feed_stats_runner_slurm.py \
  --start_date=${START_DATE} \
  --end_date=${END_DATE} \
  --script_only=False \
  --workers=0 \
  --sbatch_args="--wait --hint=nomultithread -n150 --mem-per-cpu=4G --job-name=coin2stats"

cd ../
PYTHON_CODE_SNIPPET="from xunkemgmt_client.tool.slack_noti import send_to_slack; import sys; import datetime;"
PYTHON_CODE_SNIPPET="${PYTHON_CODE_SNIPPET} send_to_slack('$TRADING_DATE <-- feed stats done: ' + str(datetime.datetime.now()), '#hft_feed', 'file')"
./pyrunner -c "${PYTHON_CODE_SNIPPET}"

conda deactivate
